package com.mzy.excel;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.alibaba.excel.write.metadata.WriteSheet;
import org.springframework.beans.BeanUtils;

import java.io.OutputStream;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author Ives
 * * @date 2021/12/30
 */
public class manySheets {
  /**
   * 参考 多Sheet分组导出
   */
//  List<PrizeInstExgListVO> instExgList = getInstExgList(queryBO);
//
//  Map<String, List<PrizeInstExgListVO>> collect = instExgList.stream().collect(Collectors.groupingBy(PrizeInstExgListVO::getActiveName));
//  ExcelWriter excelWriter = EasyExcel.write(getOutputStream("PrizeInstExgExport",response)).build();
//  int i=0;
//    for (Map.Entry<String, List<PrizeInstExgListVO>>  entry:
//          collect.entrySet()) {
//
//    List<PrizeInstExgExportVO> collect1 = entry.getValue().stream().map(instExg -> {
//      PrizeInstExgExportVO prizeInstExgExportVO = new PrizeInstExgExportVO();
//      BeanUtils.copyProperties(instExg, prizeInstExgExportVO);
//      return prizeInstExgExportVO;
//    }).collect(Collectors.toList());
//    WriteSheet sheet1 = EasyExcel.writerSheet(i, "Sheet"+i).head(PrizeInstExgExportVO.class).build();
//    excelWriter.write(collect1,sheet1);
//    i++;
//  }
//    excelWriter.finish();


//  private static OutputStream getOutputStream(String fileName, HttpServletResponse response) {
//    String filePath = fileName + ExcelTypeEnum.XLSX.getValue();
//
//    try {
//      fileName = URLEncoder.encode(filePath, StandardCharsets.UTF_8.name());
//      String contentStr = "attachment; fileName='%s';filename*=utf-8''%s";
//      String contentValue = String.format(contentStr, fileName, fileName.replaceAll("\\+", " "));
//      response.setContentType("application/octet-stream");
//      response.setHeader("Content-Type", "application/octet-stream");
//      response.addHeader("Content-Disposition", contentValue);
//      return response.getOutputStream();
//    } catch (Exception var5) {
//      throw new SystemException(var5);
//    }
//  }
}
